import GlobalSettingStore from "@/store/globalSettingStore";
import {speakChinese,stopSpeak} from "@/utils/VoiceUtil";



export default function (){

    const errorAudioURL = require("@/assets/audio/answerError.mp3")
    let errorAudio= new Audio(errorAudioURL)
    let {globalSetting} = GlobalSettingStore();

    function check(){
        return globalSetting.playAudio
    }
    function speakChinese(char:string){
        if(check()){
            stopSpeak()
            speakChinese(char)
        }
    }
    function speakEnglish(char:string){
        if(check()){
            stopSpeak()
            stopSpeak()
            speakEnglish(char)
        }
    }
    function playErrorVoice(){
        if(check()){

           errorAudio.play().then(r => console.log(r))
        }
    }
    function stopSpeak(){
        stopSpeak()
    }
    return{
        speakChinese,
        speakEnglish,
        stopSpeak,
        playErrorVoice
    }
}